﻿using MediatR;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.BuildingManagementCommandHandler
{
    public class BuildingManagementUpdaCommandHandler : IRequestHandler<BuildingManagementUpdaCommand, Results<int>>
    {
        private readonly IBuildingManagementService buildingManagementService;

        public BuildingManagementUpdaCommandHandler(IBuildingManagementService buildingManagementService)
        {
            this.buildingManagementService = buildingManagementService;
        }


        public async Task<Results<int>> Handle(BuildingManagementUpdaCommand request, CancellationToken cancellationToken)
        {
            var entity = new BuildingManagement()
            {
                BuildingManagementId = request.BuildingManagementId,
                BuildingName = request.BuildingName,
                BuildingType = request.BuildingType,
                BuildingDuty = request.BuildingDuty,
                ProductionPeason = request.ProductionPeason,
                BuildingState = request.BuildingState == 1 ? true : false,
              
                UpdateName = request.UpdateName,
                DelTime = request.DelTime,
            
                DelName = request.DelName,
                IsDel = 0,
                Remarks = request.Remarks,
                UpdateTime = DateTime.Now,
            };
            var list = await buildingManagementService.UpdaBuildingManagement(entity);
            return Results<int>.DataResult(list);
        }
    }
}
